package animationGame;

public class GeometricObject {
	public Vertex pos;
	public double width;
	public double height;
	public String color;
	
	public GeometricObject(Vertex pos){
		this(0,0,pos, "black");
	}
	public GeometricObject(){
		this(10);
	}
	public GeometricObject(double w){
		this(w,w);
	}
	public GeometricObject(double w, double h){
		this(w, h, new Vertex(0,0), "black");
	}
	public GeometricObject(double w, double h, String color){
		this(w, h, new Vertex(0,0), color);
	}
	public GeometricObject(double w, double h, Vertex poss){
		this(w,h,poss,"black");
	}
	public GeometricObject(double w, double h, Vertex poss, String c){
		pos = poss;
		width = w;
		height = h;
		color = c;
		if(width<0){
			width = -width;
			pos.setX(pos.getX()-width);
		}
		if(height<0){
			height = -height;
			pos.setY(pos.getY()-height);
		}
		
	}
	
	public Vertex getPos(){
		return pos;
	}
	
	public double getWidth(){
		return width;
	}
	
	public double getHeight(){
		return height;
	}
	
	public String toString(){
		return "width="+width+", height="+height+", pos="+pos;
	}
	
	public double circumference(){
		return 2*width+2*height;
	}
	
	public double area(){
		return width*height;
	}
	
	public boolean contains(Vertex v){
		return v.getX()<=pos.getX()+width && v.getX()>=pos.getX()	//x is within
			&& v.getY()<=pos.getY()+height && v.getY()>=pos.getY();	//y is within
	}
	
	public boolean isLargerThan(GeometricObject that){
		return this.area() > that.area();
	}
	
	public void moveTo(Vertex pos){
		this.pos = pos;
	}
	
	public void moveTo(double x, double y){
		moveTo(new Vertex(x,y));
	}
	
	public void move(Vertex v){
		moveTo(pos.add(v));
	}
	
	public boolean equals(Object thatObject){
		if(thatObject instanceof GeometricObject){
			GeometricObject that = (GeometricObject)thatObject;
			return this.pos.equals(that.pos) 
				&& this.width == that.width
				&& this.height == that.height;
		}else{
			return false;
		}
	}
	
	public boolean touch(GeometricObject that){
		return this.contains(that.getPos()) 
				|| that.contains(this.pos)
				|| this.contains(that.pos.add(new Vertex(width, height)))
				|| this.contains(that.pos.add(new Vertex(width, 0)))
				|| this.contains(that.pos.add(new Vertex(0, height)));
	}
}
